package com.lv.dhart.holder.activity.jjholdstocklist;

import static com.lv.dhart.utils.NumberUtils.amountConversion;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.lv.dhart.R;
import com.lv.dhart.beans.JJHoldStockListBeans;
import com.smart.holder.iinterface.IViewHolder;
import com.smart.holder.iinterface.IViewHolderHelper;

import java.util.List;

/**
 * Created by binny on 2018/6/1.
 * 历史上的今天
 */

public class JJHoldStockListViewHolderHelper implements IViewHolderHelper<JJHoldStockListViewHolder, JJHoldStockListBeans.DataDTO.RowsDTO> {


    @Override
    public IViewHolder initItemViewHolder(JJHoldStockListViewHolder viewHolder, View convertView) {
        viewHolder = new JJHoldStockListViewHolder();
        viewHolder.stock_code = convertView.findViewById(R.id.stock_code);
        viewHolder.end_time = convertView.findViewById(R.id.end_time);
        viewHolder.hold_num_ratio = convertView.findViewById(R.id.hold_num_ratio);
        viewHolder.stock_name = convertView.findViewById(R.id.stock_name);
        viewHolder.hold_change = convertView.findViewById(R.id.hold_change);
        viewHolder.holder_total_num = convertView.findViewById(R.id.holder_total_num);
        viewHolder.mArticleCardView = convertView.findViewById(R.id.article_card_view);
        return viewHolder;
    }

    @Override
    public void bindListDataToView(Context context, List<JJHoldStockListBeans.DataDTO.RowsDTO> list, JJHoldStockListViewHolder viewHolder, int i) {

        if (i == 0) {
            viewHolder.mArticleCardView.setBackground(context.getResources().getDrawable(R.drawable.article_card_view_shape_current_day));
        } else if (i == 1) {
            viewHolder.mArticleCardView.setBackground(context.getResources().getDrawable(R.drawable.article_card_view_shape_blue));
        } else {
            viewHolder.mArticleCardView.setBackground(context.getResources().getDrawable(R.drawable.article_card_view_shape_gold));

        }
        viewHolder.stock_code.setText(list.get(i).getStockCode());
        viewHolder.end_time.setText("日期：" + list.get(i).getEndDate().split(" ")[0]);
        viewHolder.hold_num_ratio.setText("比例：" + list.get(i).getHoldNumRatio() + " %");
        viewHolder.stock_name.setText(list.get(i).getStockName());
        String hold_change = list.get(i).getChangeRatio();
        if (TextUtils.isEmpty(hold_change)) {
            hold_change = list.get(i).getHoldChange();
        }
        viewHolder.hold_change.setText(hold_change);
        viewHolder.holder_total_num.setText(String.valueOf(amountConversion(Double.parseDouble(list.get(i).getHoldNum()))));
    }

}
